package com.lmf.vod.controller;

import com.lmf.handler.Exception.LmfException;
import com.lmf.resultCode.R;
import com.lmf.vod.service.VodService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Api(description = "vod控制管理")
@CrossOrigin
@RestController
@RequestMapping("/edu_vod/video")
public class VodController {

    @Autowired
    private VodService vodService;

    @ApiOperation("上传视频到阿里云，返回视频id")
    @PostMapping("/uploadAliyunVideo")
    public R uploadAliyunVideo(MultipartFile file){
        //返回上传视频的id
        String videoId = vodService.uploadVideoAliyun(file);
        return R.ok().data("videoId",videoId);
    }

    @ApiOperation("根据视频id，删除阿里云上面对应的视频")
    @DeleteMapping("/deleteVideoById/{videoId}")
    public R deleteVideoById(@PathVariable("videoId") String videoId) throws LmfException {
        vodService.deleteVideoById(videoId);
        return R.ok();
    }

    @ApiOperation("根据视频id，批量删除阿里云上面对应的小节视频")
    @DeleteMapping("/delete-batch")
    public R deleteBatchVideo(@RequestParam("videoIdList") List<String> videoIdList) throws LmfException {
        vodService.deleteBatchVideo(videoIdList);
        return R.ok();
    }
}
